<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>站点设置</legend>
            <div>
                <form class="layui-form layui-form-pane" lay-filter="webset">

                    <div class="layui-form-item">
                        <label class="layui-form-label">网站标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" autocomplete="off" placeholder="请输入网站标题"
                                class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">网站副标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="subheading" autocomplete="off" placeholder="请输入网站副标题"
                                class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">网站域名</label>
                        <div class="layui-input-block">
                            <input type="text" name="domain" autocomplete="off" placeholder="请输入网站域名"
                                class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">站长邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" autocomplete="off" placeholder="请输入站长邮箱"
                                class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">版权信息</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入版权信息，支持HTML代码" name="copyright" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">网站模板</label>
                            <div class="layui-input-inline">
                                <select name="pc_tem" lay-filter="aihao">
                                    {volist name=":getCatalog()" id="data"}
                                    <option value="{$data}">{$data}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">自适应手机</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="adapt" value="true" title="开启">
                                <input type="radio" name="adapt" value="false" title="关闭">
                            </div>
                            <div class="layui-form-mid layui-word-aux">自适应模板可以选择关闭此项</div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">手机模板</label>
                            <div class="layui-input-inline">
                                <select name="m_tem" lay-filter="aihao">
                                    {volist name=":getCatalog()" id="data"}
                                    <option value="{$data}">{$data}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">站点状态</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="website" value="true" title="开启">
                                <input type="radio" name="website" value="false" title="关闭">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">关闭提示</label>
                            <div class="layui-input-inline">
                                <input type="text" name="msg" autocomplete="off" placeholder="站点暂时关闭，请稍后访问"
                                    class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">网站LOGO</label>
                            <div class="layui-input-inline">
                                <input type="text" id="logourl" name="logo" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline">
                                <!-- <input type="file" name="uplogo" id="fileicon"
                                    style="position: absolute; width: 190px; height: 100%; display: inline-block; opacity: 0;"> -->

                                <button type="button" class="layui-btn" id="uplogo">上传LOGO</button>
                            </div>
                        </div>

                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">统计代码</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入统计代码，支持HTML代码" name="census" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="webset">保存</button>
                    </div>
                </form>
            </div>
        </fieldset>
    </div>


</div>

<script>
    layui.use(['form', "upload", 'lycms'], function () {
        var form = layui.form,
            layer = layui.layer,
            lycms = layui.lycms,
            upload = layui.upload;
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //LOGO上传
        var uploadInst = upload.render({
            elem: '#uplogo', //绑定元素
            url: '/ask/action/up/uplogo', //上传接口
            field: 'uplogo',
            data: {
                type: "logo"
            },
            done: function (res) {
                layer.msg(res.msg);
                //上传完毕回调
                $('#logourl').val(res.data.imgUrl);
            }
            , error: function () {
                //请求异常回调
            }
        });

        //监听提交
        form.on('submit(webset)', function (data) {
            lycms.websetOperate(data);
            return false;
        });

        //头像window
        $(document).onload = function () {
            var input = document.querySelector('input[type=file]');
            input.onchange = function (e) {
                if ($('#fileicon').val() != '') {
                    fd = new FormData();
                    fd.append("uplogo", $('#fileicon').val());
                    $.ajax({
                        url: '/user/upimg',
                        type: 'POST',
                        timeout: 3000,
                        dataType: 'JSON',
                        contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                        data: fd,
                        contentType: false, //不设置内容类型
                        processData: false, //不处理数据
                        success: function (data) {
                            if (data.code == 200) {
                                layer.msg(data.msg);
                            } else {
                                layer.msg(data.msg);
                            }
                        },
                        error: function (XMLResponse) {
                            //异常捕获
                            layer.msg(XMLResponse.responseText);
                        }
                    });
                }
            }
        }

        // 页面初始化
        $(document).ready(function () {
            //获取初始信息
            $.post("/v1/admin/data/webset", function (data, status) {
                //表单初始赋值
                form.val('webset', data);
            });
        });

    });
</script>